package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MenuDao;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuService;
import com.itheima.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
@Service(interfaceClass = MenuService.class)
@Transactional
public class MenuServiceImpl implements MenuService {
    @Autowired
   private MenuDao menuDao;
    @Override
    public List<Menu> getMenus(String userName) {
        List<Menu> rsList = new ArrayList<>();//结果返回菜单
        //查询一级菜单
        List<Menu> menuList1 = menuDao.getMenus1(userName);
        //查询二级菜单
        List<Menu> menuList2 = menuDao.getMenus2(userName);
        //将二级菜单添加至一级菜单
        for (Menu menuFu : menuList1) {
            Integer id = menuFu.getId();
            for (Menu menuChildren : menuList2) {
                if (id == menuChildren.getParentMenuId()){
                    menuFu.getChildren().add(menuChildren);
                }
            }
        }

        return menuList1;
    }

}
